package com.um.jdy.platform.sharing.controller;

import com.um.jdy.platform.member.entity.dto.MemberPageDTO;
import com.um.jdy.platform.sharing.entity.vo.SharingReceiverVO;
import com.um.jdy.platform.sharing.manager.SharingReceiverManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;


/**
 * 分账管理
 *
 * @author 邓南辉
 * 日期 2023/5/11
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/cms/sharing/receiver")
@Api(tags = "分账接收方")
@ApiPermission("sharing_receiver")
@TokenRequired
public class SharingReceiverController extends BaseController<SharingReceiverManager> {


    /**
     * 查询分页
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Response<Page<SharingReceiverVO>> getFeePage(@RequestBody MemberPageDTO params){
        PageParams pageParams = params.toPageParams(new String[]{"mobile","nickname"},new String[]{"u.mobile","u.nickname"});
        return manager.getUserPage(pageParams);
    }

    /**
     * 添加分账接收方
     * @return
     */
    @ApiPermission("add")
    @ApiOperation(value = "删除分账用户")
    @PostMapping("/{userId}")
    public Response add(@ApiParam(value = "用户id") @PathVariable String userId){
        return manager.addReceiver(userId);
    }

    /**
     * 删除分账接收方
     * @return
     */
    @ApiPermission("delete")
    @ApiOperation(value = "删除分账用户")
    @DeleteMapping("/{id}")
    public Response remove(@ApiParam(value = "主键id") @PathVariable String id){
        return manager.removeReceiver(id);
    }

}
